home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / wtek0693.zip / OOPALLEY.ZIP / XQUEUE.CPP < prev    next >
C/C++ Source or Header  |  1993-04-27  |  3KB  |  108 lines

  1. //#include <stream.h>
  2. #define DISPLAY_ARRAYOB_INFO
  3. #ifdef DISPLAY_ARRAYOB_INFO
  4. #include "arrayob.h"
  5. #endif
  6.  
  7.  
  8. #include "queue.h"
  9.  
  10.  
  11. #if 1
  12. // required only by test application
  13. #include "point.h"
  14. #include "conio.h"
  15. #endif
  16.  
  17.  
  18. void printRemove(Queue& q)
  19. {
  20.     cout << "Remove and print each object in Queue:\n";
  21.     while(q.size()>0)
  22.     {
  23.         cout << *q.next();
  24.         cout << " | ";
  25.     }
  26.     cout << "=======\n";
  27. }
  28.  
  29. #pragma argsused
  30. // q is used with preprocessor sizeof operator
  31. // but BC++ 3.1 reports that q is not used
  32. // The above pragma turns off the warning.
  33. void printObjectSizes(Queue& q)
  34. {
  35.     cout << "sizeof(q):" << sizeof(q) << "\n";
  36.     cout << "sizeof(Object):" << sizeof(Object) << "\n";
  37.     cout << "sizeof(Point):" << sizeof(Point) << "\n";
  38.     cout << "sizeof(Queue):" << sizeof(Queue) << "\n";
  39. #ifdef DISPLAY_ARRAYOB_INFO
  40.     cout << "sizeof(ArrayOb):" << sizeof(ArrayOb) << "\n";
  41. #endif
  42. }
  43.  
  44. #define BATCH
  45. #ifdef BATCH
  46. // useful for batch output verification
  47. inline int getch()  // don't wait for keypress
  48. {
  49.     cout << "========================================\n";
  50.     return 0;
  51. #endif
  52. main()
  53. {
  54.     cout << "hello, world\n";
  55.     Queue q(10);
  56.     cout <<  "q created\n";
  57.     cout <<  "q capacity: " << q.capacity() << "\n";
  58.     cout <<  "q size: " << q.size() << "\n";
  59.     printObjectSizes(q);
  60.     getch();
  61.  
  62. for (int i=0; i<2; i++)
  63. {
  64.     q.nextPut(*new Point(i,1));
  65.     q.nextPut(*new Point(i,2));
  66.     q.nextPut(*new Point(i,3));
  67.  
  68.     q.state();    printRemove(q);    getch();
  69.  
  70.     q.nextPut(*new Point(i,4));
  71.     q.nextPut(*new Point(i,5));
  72.     q.nextPut(*new Point(i,6));
  73.     q.nextPut(*new Point(i,7));
  74.     q.nextPut(*new Point(i,8));
  75.     q.nextPut(*new Point(i,9));
  76.     q.nextPut(*new Point(i,10));
  77.  
  78.     cout << "q should be filled:\n";
  79.  
  80.     q.state();    printRemove(q);    getch();
  81. }
  82.     i = 3;
  83.     q.nextPut(*new Point(i,1));
  84.     q.nextPut(*new Point(i,2));
  85.     q.nextPut(*new Point(i,3));
  86.  
  87.     q.state();      q.printOn(cout);       getch();
  88.  
  89.     q.nextPut(*new Point(i,4));
  90.     q.nextPut(*new Point(i,5));
  91.     q.nextPut(*new Point(i,6));
  92.     q.nextPut(*new Point(i,7));
  93.     q.nextPut(*new Point(i,8));
  94.     q.nextPut(*new Point(i,9));
  95.     q.nextPut(*new Point(i,10));
  96.  
  97.     q.state();    q.printOn(cout);
  98.     cout << "Next statement should resize q\n";
  99.     getch();
  100.  
  101.     q.nextPut(*new Point(i,11));
  102.     q.state();  getch();  printRemove(q);   getch();
  103.  
  104.     return 0;
  105. }
  106.  
  107.